import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../ViewModel/meViewModel.dart';

final TextEditingController controller = TextEditingController();

class EditMeRemark extends StatelessWidget {
  const EditMeRemark({super.key});

  Future<bool> postRemark() async {
    try {
      var params = {
        "remark": controller.text,
      };
      return await Api().postRemark(params,false);
    } catch (e) {
      print('Error getting me data: $e');
      return false;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[100],
      appBar: AppBar(
          title: const Text("编辑简介"),
          leading: IconButton(
              onPressed: () async {
                if (await postRemark()) {
                  Navigator.pop(context);
                  controller.text = "";
                }
              },
              icon: const Icon(Icons.arrow_back_ios_new_rounded))),
      body: buildContainer(),
    );
  }

  Container buildContainer() {
    return Container(
      padding: const EdgeInsets.all(16.0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          ClipRRect(
            borderRadius: BorderRadius.circular(10),
            child: TextFormField(
              controller: controller,
              maxLines: 5,
              maxLength: 120,
              decoration: const InputDecoration(
                hintText: '介绍一下自己',
                border: InputBorder.none, // 去掉边框
                filled: true,
                fillColor: Colors.white,
              ),
            ),
          ),
          const Text('请修改您的简介，返回后自动保存',
              style: TextStyle(color: Colors.black54, fontSize: 13)),
        ],
      ),
    );
  }
}
